package com.telecom.cms.actions;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.telecom.cms.dao.SEG_BIZ_ATOM_DEFDAO;
import com.telecom.cms.dao.GetConnect;

import com.telecom.cms.dto.*;


/**
 * @author yueyingnishang
 * 
 */
public class AtomRsetAction extends Action {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub

		List list = (List) request.getSession().getAttribute("AtomList");

		Connection con = GetConnect.getCsConnection();
		
		SEG_BIZ_ATOM_DEFDAO dao = new SEG_BIZ_ATOM_DEFDAO(con);
		
		List atomlist = new ArrayList();

		for (int i = 0; i < list.size(); i++) {

			ShowatomDTO dto = (ShowatomDTO) list.get(i);
			
			SEG_BIZ_ATOM_DEFDTO seg_BIZ_ATOM_DEFDTO = new SEG_BIZ_ATOM_DEFDTO();
			
			seg_BIZ_ATOM_DEFDTO = dao.findById(dto.getAtomid());
			
			atomlist.add(seg_BIZ_ATOM_DEFDTO);

		}
		request.setAttribute("AddOrModiFlag", "Modi");
        request.setAttribute("Atoms", atomlist);
        request.getSession().setAttribute("AtomList", list);
		
		return mapping.findForward("success");
	}
}
